<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF文字提取</title>
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
    <div class="container">
        <h1>PDF文字提取</h1>
        <a href="/" class="back-btn">返回首页</a>
        <div class="upload-container">
            <form id="upload-form" enctype="multipart/form-data">
                <input type="file" id="pdf-input" accept=".pdf" required>
                <button type="submit">开始提取</button>
            </form>
            <div id="result" class="result-container">
                <div id="text-content"></div>
                <button id="download-word" style="display: none;">下载Word文档</button>
            </div>
        </div>
    </div>
    <script>
        document.getElementById('upload-form').onsubmit = async function(e) {
            e.preventDefault();
            const formData = new FormData();
            formData.append('pdf', document.getElementById('pdf-input').files[0]);
            
            const textContent = document.getElementById('text-content');
            textContent.innerHTML = '正在处理中...';
            
            try {
                const response = await fetch('/api/extract-pdf', {
                    method: 'POST',
                    body: formData
                });
                const data = await response.json();
                
                if (!data.success) {
                    throw new Error(data.error || '提取失败');
                }
                
                textContent.innerHTML = `
                    <div class="original-text">
                        <h3>原文内容：</h3>
                        <p>${data.original_text}</p>
                    </div>
                    <div class="ai-analysis">
                        <h3>AI分析：</h3>
                        <p>${data.ai_result}</p>
                    </div>
                `;
                
                const downloadBtn = document.getElementById('download-word');
                downloadBtn.style.display = 'block';
                downloadBtn.onclick = () => {
                    window.location.href = '/download-word/' + data.filename;
                };
            } catch (error) {
                console.error('Error:', error);
                textContent.innerHTML = '处理失败：' + error.message;
            }
        };
    </script>
</body>
</html> 